package com.cade.agriculturemall.view.home.search;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.cade.agriculturemall.base.BasePresenter;
import com.cade.agriculturemall.model.GoodsDetailEntity;

import java.util.List;

/**
 * Created by hshunxin on 2018/2/6.
 */

public class SearchPresenter extends BasePresenter<SearchContract.IView> implements SearchContract.IPresenter {
    public SearchPresenter(SearchContract.IView view) {
        super(view);
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void query(String keyWord) {
        mView.dismissProgress();
        AVQuery<GoodsDetailEntity> query = new AVQuery<>("ClassifyGoodsThird");
        query.whereContains("category_name", keyWord);
        query.findInBackground(new FindCallback<GoodsDetailEntity>() {
            @Override
            public void done(List<GoodsDetailEntity> list, AVException e) {
                if (e == null) {
                    mView.getData(list);
                } else {
                    e.printStackTrace();
                }
                mView.dismissProgress();
            }
        });
    }
}
